<?php
namespace Home\Controller;
use Think\Controller;
class SureaddressController extends PublicController {
	
    public function sureaddress(){
		$this->assign("k",CONTROLLER_NAME);
		$this->assign("f",ACTION_NAME);
		// $this->addressShow();
		// $this->changeAddress();
		$uid = $_GET['uid'];
		$this->assign("uid",$uid);
		$this->display();
		
	}
	

	public function addresslist(){
		
		$addr = M('shopaddress')->select();
		foreach($addr as $k=>$v){
			
			$zhuangtai[] = $v['status'];
		}
		$this->assign("zhuangtai",$zhuangtai);
		echo json_encode($addr);
		
	}
	//ajax 修改地址状态
	public function changeAddress(){
		
		$userid = $_POST["p_id"];
		$id = $_POST["id"];
		$status = $_POST["status"];
		$data['status'] = $status;
		if($status == '2'){
			$qita = M('shopaddress')->where("p_id = '$userid'")->select($data);
			foreach($qita as $k=>$v){
				$qitaid = $v['id'];
				$data['status']='2';
				M('shopaddress')->where("id = $qitaid")->save($data);
			}
			$data['status']='1';
			M('shopaddress')->where("id = $id")->save($data);
			
		}else{
			$data['status']='2';
			M('shopaddress')->where("id = $id")->save($data);
		}
		
	}
	
	
}